#include "gamemenu.h"
#include "ui_gamemenu.h"

GameMenu::GameMenu(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::GameMenu)
{
    ui->setupUi(this);

    //设置固定尺寸
    this->setFixedSize(600,900);

    //设置标题
    this->setWindowTitle("推箱子BoxMan");

    //设置图标(QPixMap也可)
    this->setWindowIcon(QIcon(":/res/man_destiny.png"));

    //创建选关场景
    selectWindow = new SelectWindow;

    //创建play按钮
    GPushButton * playBtn = new GPushButton(":/res/PLAY.png",":/res/playBtn.png");
    playBtn->setParent(this);
    playBtn->move(this->width() * 0.5 - playBtn->width() * 0.5, this->height() * 0.6);

    //点击play进入选关
    connect(playBtn, &GPushButton::clicked,[=]{
        qDebug()<< "进入到选关场景";

        //延时跳转，以展示动画
        QTimer::singleShot(300,this,[=]{
            this->selectWindow->show();//选关场景 显示
            this->hide();//当前窗口 隐藏
        });
    });

    //监听选关场景中的返回信号
    connect(this->selectWindow,&SelectWindow::ChooseSceneBack,[=]{
        this->show();
        this->selectWindow->hide();
    });

    //创建帮助场景
    helpWindow = new HelpWindow;

    //创建help按钮
    GPushButton * helpBtn = new GPushButton(":/res/HELP.png",":/res/helpBtn.png");
    helpBtn->setParent(this);
    helpBtn->move(this->width() * 0.5 - helpBtn->width() * 0.5, this->height() * 0.7);

    //点击help进入帮助
    connect(helpBtn, &GPushButton::clicked,[=]{
        qDebug()<< "进入到帮助场景";

        //延时跳转，以展示动画
        QTimer::singleShot(300,this,[=]{
            this->helpWindow->show();//帮助场景 显示
            //this->hide();//当前窗口 隐藏
        });
    });

    //创建exit按钮
    GPushButton *exitBtn = new GPushButton(":/res/EXIT.png",":/res/exitBtn.png");
    exitBtn->setParent(this);
    exitBtn->move(this->width()*0.5-exitBtn->width()*0.5,this->height()*0.8);

    //点击exit退出
    connect(exitBtn, &GPushButton::clicked,[=]{
        qDebug()<< "游戏退出";

        //延时跳转，以展示动画
        QTimer::singleShot(300,this,[=]{
            this->close();
        });
    });

}

GameMenu::~GameMenu()
{
    delete ui;
}

void GameMenu::paintEvent(QPaintEvent *)
{
    //创建画家对象
    QPainter painter(this);
    //创建PixMap对象
    QPixmap pix;
    //加载图片
    pix.load(":/res/MenubackG.jpeg");
    //画背景图 重载的后两个参数是拉伸
    painter.drawPixmap(0,0,600,900,pix);
    //加载标题资源
    pix.load(":/res/tittle.png");
    //拉伸图片
    pix = pix.scaled(pix.width()*0.2,pix.height()*0.25);
    //画标题boxman
    painter.drawPixmap(this->width()*0.5-pix.width()*0.5,130,pix);

}

